<template>
  <div class="chip" :class="[type ? `chip--${type}` : '']">
    <div class="content">
      <slot />
      <span v-if="closable" class="closable" @click="handleClose">
        <i class="el-icon-close" />
      </span>
    </div>
  </div>
</template>

<script>
export default {
  name: "Chip",
  props: {
    type: {
      type: String,
      default: "",
    },
    closable: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    handleClose() {
      this.$emit("close");
    },
  },
};
</script>

<style lang="scss" scoped>
/* stylelint-disable */
.chip {
  display: inline-block;
  padding: 0 10px;
  margin-right: 2px;
  vertical-align: middle;
  border-radius: 20px;

  .content {
    display: flex;
    align-items: center;
    min-height: 28px;
    font-size: 12px;

    :deep(.el-avatar) {
      width: 24px;
      height: 24px;
      margin-right: 5px;
      margin-left: -8px;
      line-height: 24px;
    }

    .closable {
      width: 20px;
      height: 20px;
      margin-right: -4px;
      margin-left: 5px;
      font-size: 14px;
      line-height: 20px;
      color: #fff;
      text-align: center;
      cursor: pointer;
      background-color: #ccc;
      border-radius: 50%;

      &:hover {
        opacity: 0.7;
      }
    }
  }

  &--primary {
    color: #fff;
    background-color: #409eff;

    .content .closable {
      background-color: darken(#409eff, 10);
    }
  }

  &--success {
    color: #fff;
    background-color: #67c23a;

    .content .closable {
      background-color: darken(#409eff, 10);
    }
  }

  &--info {
    color: #fff;
    background-color: #909399;

    .content .closable {
      background-color: darken(#909399, 10);
    }
  }

  &--warning {
    color: #fff;
    background-color: #e6a23c;

    .content .closable {
      background-color: darken(#e6a23c, 10);
    }
  }

  &--danger {
    color: #fff;
    background-color: #f56c6c;

    .content .closable {
      background-color: darken(#f56c6c, 10);
    }
  }
}
</style>
